<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>搜索结果</title>
    <link rel="stylesheet" href="/public/static/css/wangeditor.css">
    <link rel="stylesheet" href="/public/static/css/view.css">
    <link rel="stylesheet" href="/public/static/css/layui.css">
    <link rel="stylesheet" href="/public/static/css/out.css">
    <script src="/public/static/js/jquery.js"></script>
    <script src="/public/static/js/jsrender.js"></script>
    <script src="/public/static/js/layui.js"></script>
</head>

<body>
<div class="main">
    <?php view('common/header'); ?>
    <div class="col-sm-9 col-xs-12" id="postsdetail" style="margin-top: 75px;">
        <div id="demo-laypage-normal-1"></div>
    </div>
    <div class="foot">
        <div class="container">
            <div class="row">
                <div class="col-xs-12">
                </div>
            </div>
        </div>
    </div>
</div>

<script id="posts_detail" type="text/x-jsrender">
    {{for commens}}
         <div class="post-list">
                <h2><a href="/?a=article&tid={{: tid}}">{{: textname}}</a></h2>
                <div class="flex">
                <p class="date"><i class="layui-icon layui-icon-time"></i> &nbsp; {{: created}}</p>
                <p class="print"></p>
                <p> <i class="layui-icon layui-icon-username"></i> &nbsp;创建者:&nbsp; <span class="creator">{{: creator}}</span></p>
                </div>
             </div>
    {{/for}}
  </script>

<script>
    var loc = location.href;
    var n1 = loc.length;//地址的总长度
    var n2 = loc.indexOf("=");//取得=号的位置
    var textn = '<?=$_GET['textn']??'';?>';//从=号后面的内容
    $(function ($) {
        $.post('<?=getUrl('api','search','index')?>', { text: textn }, function (res) {
            console.log(res)
            if(res.code==0){
                alert(res.msg);
            }
            if(res.count==0){
                alert("没有找到相关内容");
                window.location.href = "/";
            }
            else{
                var html = $('#posts_detail').render({ commens: res.list });
                $('#postsdetail').html(html);
            }
        });
    })
</script>

<?php view('common/footer'); ?>
</body>
</html>